package cn.smile.controller.core;

import cn.smile.bean.dto.core.RoleInfoDTO;
import cn.smile.bean.form.core.role.RoleAddForm;
import cn.smile.bean.form.core.role.RoleQueryForm;
import cn.smile.bean.form.core.role.RoleRelUpdateForm;
import cn.smile.bean.form.core.role.RoleUpdateForm;
import cn.smile.business.core.IRoleService;
import cn.smile.commons.response.MyResult;
import com.baomidou.mybatisplus.core.metadata.IPage;
import jakarta.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import jakarta.annotation.Resource;
import java.util.List;

/**
 * @author smile-jt
 */
@Slf4j
@RestController
@RequestMapping("api/role")
public class RoleController {

    @Resource
    private IRoleService service;

    @GetMapping(value = "checkCode")
    public MyResult<Boolean> checkCode(@RequestParam("roleCode") String roleCode) {
        return MyResult.OK(service.checkCode(roleCode));
    }

    @PostMapping("query/page")
    public MyResult<IPage<RoleInfoDTO>> queryPage(@RequestBody RoleQueryForm form) {
        return MyResult.OK(service.queryPage(form));
    }

    @PostMapping("query/list")
    public MyResult<List<RoleInfoDTO>> queryList(@RequestBody RoleQueryForm form) {
        return MyResult.OK(service.queryList(form));
    }

    @PostMapping(value = "addInfo")
    public MyResult<Boolean> addInfo(@Valid @RequestBody RoleAddForm form) {
        return MyResult.OK(service.addInfo(form));
    }

    @PostMapping(value = "updateInfo")
    public MyResult<Boolean> updateInfo(@Valid @RequestBody RoleUpdateForm form) {
        return MyResult.OK(service.updateInfo(form));
    }

    @PostMapping(value = "updateRel")
    public MyResult<Boolean> updateRel(@Valid @RequestBody RoleRelUpdateForm form) {
        return MyResult.OK(service.updateRel(form));
    }

    @DeleteMapping("delRoleByWeb/{roleId}")
    public MyResult<Boolean> delete(@PathVariable("roleId") String roleId) {
        return MyResult.OK(service.delById(roleId));
    }
}
